// core/Assert.cpp


#include <stdio.h>

#include "Assert.h"
#include "Debug.h"

#ifdef _ASSERT_ENABLE

#include <windows.h>

#define MAX_MESSAGE_LEN		(1024)

void Assert_Break()
{
	__asm
	{
		int 3
	}
}

void Assert_OutputText( const char * pText)
{
	if (pText)
	{
		Debug_Output(pText);
	}
}

void Assert_OutputMessage( const char * pText, const char * pMessage, const char * pFunc, const char * pFileName, int iLine )
{
	if( !pMessage )
		pMessage = "";

	static char szText[MAX_MESSAGE_LEN];
	sprintf_s( szText, MAX_MESSAGE_LEN, pText, pMessage, pFunc, pFileName, iLine );

	Assert_OutputText( szText );
}

void Assert_Function( const char * pText, bool & bIgnoreAlways, const char * pFunc, int iLine, const char * pFile )
{
	char szText[MAX_MESSAGE_LEN];

	// Abort, retry, ignore.
	sprintf_s( szText, MAX_MESSAGE_LEN, "Assert hit: %s\n func %s(), file %s line %d\n\nBreak (ABORT), Ignore once (RETRY), or ignore always(IGNORE)", pText, pFunc, pFile, iLine );

	int iRet = MessageBoxA( NULL, szText, "ASSERT", MB_ABORTRETRYIGNORE );

	if( iRet == IDABORT )
	{	// Break
		Assert_Break();
	}
	else if( iRet == IDRETRY )
	{	// Ignore once
	}
	else if( iRet == IDIGNORE )
	{	// Just drop through, actually.
		bIgnoreAlways = true;
	}
}

#endif